/*
 * JdhView.java
 */

package jdh;

import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.Timer;
import javax.swing.JFrame;

/**
 * The application's main frame.
 */
public class JdhView extends FrameView {

    public JdhView(SingleFrameApplication app) {
        super(app);

        initComponents();

        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        //statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String)(evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer)(evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });

        // USER INITIAL
        userInitial();
    }

    private void userInitial(){
        getFrame().addWindowListener(new java.awt.event.WindowAdapter() {
                @Override
                public void windowClosing(java.awt.event.WindowEvent e) {
                    backend.disconnect();
                    System.exit(0);
                }
        });

        backend = Backend.getDefaultBackend();
        login();
        System.out.println("User initial finished.");
    }

    @Action
    public void login(){
        if (loginDialog == null){
            JFrame mainFrame = JdhApp.getApplication().getMainFrame();
            loginDialog = new JdhLoginDialog(mainFrame, true, backend);
            loginDialog.setLocationRelativeTo(mainFrame);
        }
        JdhApp.getApplication().show(loginDialog);
        this.currentUserID = loginDialog.currentUserID;
        this.currentUserType = loginDialog.currentUserType;

        backend.connect();
        DataModel.setBackend(backend);
        tabbedPanelInitial();
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = JdhApp.getApplication().getMainFrame();
            aboutBox = new JdhAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        JdhApp.getApplication().show(aboutBox);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        tabbedPanel = new javax.swing.JTabbedPane();
        introPanel = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        userManagerPanel = new javax.swing.JPanel();
        jPanel14 = new javax.swing.JPanel();
        userManagerTypeTeacher = new javax.swing.JRadioButton();
        userManagerTypeStudent = new javax.swing.JRadioButton();
        userManagerTypeAdmin = new javax.swing.JRadioButton();
        userSearch = new javax.swing.JTextField();
        deleteUserButton = new javax.swing.JButton();
        addUserButton = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        userTable = new javax.swing.JTable();
        lectureManagerPanel = new javax.swing.JPanel();
        addLectureButton = new javax.swing.JButton();
        deleteLectureButton = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        lectureTable = new javax.swing.JTable();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane7 = new javax.swing.JScrollPane();
        dependenceList = new javax.swing.JList();
        addDependenceButton = new javax.swing.JButton();
        deleteDependenceButton = new javax.swing.JButton();
        lectureBox = new javax.swing.JComboBox();
        teacherPanel = new javax.swing.JPanel();
        gotoClassFromTeacherButton = new javax.swing.JButton();
        jScrollPane8 = new javax.swing.JScrollPane();
        teacherTable = new javax.swing.JTable();
        planSearch1 = new javax.swing.JTextField();
        markFromTeacherPanel = new javax.swing.JPanel();
        markFromTeacherText = new javax.swing.JTextField();
        markFromTeacherButton = new javax.swing.JButton();
        jScrollPane5 = new javax.swing.JScrollPane();
        markFromTeacherTable = new javax.swing.JTable();
        studentPanel = new javax.swing.JPanel();
        gotoClassFromStudentButton = new javax.swing.JButton();
        planSearch2 = new javax.swing.JTextField();
        jScrollPane9 = new javax.swing.JScrollPane();
        studentTable = new javax.swing.JTable();
        markFromStudentPanel = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        markTable = new javax.swing.JTable();
        markButton = new javax.swing.JButton();
        markText = new javax.swing.JTextField();
        classInfoPanel = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        classInfoTable = new javax.swing.JTable();
        planSearch3 = new javax.swing.JTextField();
        registerPanel = new javax.swing.JPanel();
        registerButton = new javax.swing.JButton();
        jScrollPane6 = new javax.swing.JScrollPane();
        registerTable = new javax.swing.JTable();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        menuSwitchAccount = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JSeparator();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();
        userManagerTypeGroup = new javax.swing.ButtonGroup();
        userType = new javax.swing.ButtonGroup();

        mainPanel.setName("mainPanel"); // NOI18N
        mainPanel.setLayout(new javax.swing.BoxLayout(mainPanel, javax.swing.BoxLayout.LINE_AXIS));

        tabbedPanel.setName("学生注册"); // NOI18N
        tabbedPanel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tabbedPanelMouseClicked(evt);
            }
        });

        introPanel.setName("欢迎您！"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(jdh.JdhApp.class).getContext().getResourceMap(JdhView.class);
        jLabel6.setFont(resourceMap.getFont("jLabel6.font")); // NOI18N
        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        javax.swing.GroupLayout introPanelLayout = new javax.swing.GroupLayout(introPanel);
        introPanel.setLayout(introPanelLayout);
        introPanelLayout.setHorizontalGroup(
            introPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(introPanelLayout.createSequentialGroup()
                .addGap(237, 237, 237)
                .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(245, 245, 245))
        );
        introPanelLayout.setVerticalGroup(
            introPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(introPanelLayout.createSequentialGroup()
                .addGap(172, 172, 172)
                .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(215, 215, 215))
        );

        tabbedPanel.addTab(resourceMap.getString("欢迎您！.TabConstraints.tabTitle"), introPanel); // NOI18N

        userManagerPanel.setName("用户管理"); // NOI18N

        jPanel14.setName("jPanel14"); // NOI18N

        userManagerTypeGroup.add(userManagerTypeTeacher);
        userManagerTypeTeacher.setText(resourceMap.getString("userManagerTypeTeacher.text")); // NOI18N
        userManagerTypeTeacher.setName("userManagerTypeTeacher"); // NOI18N
        userManagerTypeTeacher.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                userManagerTypeTeacherActionPerformed(evt);
            }
        });

        userManagerTypeGroup.add(userManagerTypeStudent);
        userManagerTypeStudent.setText(resourceMap.getString("userManagerTypeStudent.text")); // NOI18N
        userManagerTypeStudent.setName("userManagerTypeStudent"); // NOI18N
        userManagerTypeStudent.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                userManagerTypeStudentStateChanged(evt);
            }
        });
        userManagerTypeStudent.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                userManagerTypeStudentActionPerformed(evt);
            }
        });

        userManagerTypeGroup.add(userManagerTypeAdmin);
        userManagerTypeAdmin.setSelected(true);
        userManagerTypeAdmin.setText(resourceMap.getString("userManagerTypeAdmin.text")); // NOI18N
        userManagerTypeAdmin.setName("userManagerTypeAdmin"); // NOI18N
        userManagerTypeAdmin.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                userManagerTypeAdminActionPerformed(evt);
            }
        });

        userSearch.setFont(resourceMap.getFont("userSearch.font")); // NOI18N
        userSearch.setText(resourceMap.getString("userSearch.text")); // NOI18N
        userSearch.setName("userSearch"); // NOI18N

        deleteUserButton.setText(resourceMap.getString("deleteUserButton.text")); // NOI18N
        deleteUserButton.setName("deleteUserButton"); // NOI18N
        deleteUserButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteUserButtonActionPerformed(evt);
            }
        });

        addUserButton.setText(resourceMap.getString("addUserButton.text")); // NOI18N
        addUserButton.setName("addUserButton"); // NOI18N
        addUserButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addUserButtonActionPerformed(evt);
            }
        });

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        userTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3"
            }
        ));
        userTable.setName("userTable"); // NOI18N
        jScrollPane1.setViewportView(userTable);
        userTable.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("userTable.columnModel.title0")); // NOI18N
        userTable.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("userTable.columnModel.title1")); // NOI18N
        userTable.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("userTable.columnModel.title2")); // NOI18N

        javax.swing.GroupLayout jPanel14Layout = new javax.swing.GroupLayout(jPanel14);
        jPanel14.setLayout(jPanel14Layout);
        jPanel14Layout.setHorizontalGroup(
            jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel14Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 758, Short.MAX_VALUE)
                    .addGroup(jPanel14Layout.createSequentialGroup()
                        .addComponent(addUserButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(deleteUserButton)
                        .addGap(122, 122, 122)
                        .addComponent(userManagerTypeAdmin)
                        .addGap(18, 18, 18)
                        .addComponent(userManagerTypeTeacher)
                        .addGap(18, 18, 18)
                        .addComponent(userManagerTypeStudent)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 131, Short.MAX_VALUE)
                        .addComponent(userSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 209, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        jPanel14Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {userManagerTypeStudent, userManagerTypeTeacher});

        jPanel14Layout.setVerticalGroup(
            jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel14Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(userSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(userManagerTypeAdmin)
                    .addComponent(userManagerTypeTeacher)
                    .addComponent(userManagerTypeStudent)
                    .addComponent(addUserButton)
                    .addComponent(deleteUserButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 389, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout userManagerPanelLayout = new javax.swing.GroupLayout(userManagerPanel);
        userManagerPanel.setLayout(userManagerPanelLayout);
        userManagerPanelLayout.setHorizontalGroup(
            userManagerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel14, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        userManagerPanelLayout.setVerticalGroup(
            userManagerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel14, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        tabbedPanel.addTab(resourceMap.getString("用户管理.TabConstraints.tabTitle"), userManagerPanel); // NOI18N

        lectureManagerPanel.setName("课程管理"); // NOI18N

        addLectureButton.setText(resourceMap.getString("addLectureButton.text")); // NOI18N
        addLectureButton.setName("addLectureButton"); // NOI18N
        addLectureButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addLectureButtonActionPerformed(evt);
            }
        });

        deleteLectureButton.setText(resourceMap.getString("deleteLectureButton.text")); // NOI18N
        deleteLectureButton.setName("deleteLectureButton"); // NOI18N
        deleteLectureButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteLectureButtonActionPerformed(evt);
            }
        });

        jScrollPane3.setName("jScrollPane3"); // NOI18N

        lectureTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        lectureTable.setName("lectureTable"); // NOI18N
        lectureTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lectureTableMouseClicked(evt);
            }
        });
        jScrollPane3.setViewportView(lectureTable);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel2.border.title"))); // NOI18N
        jPanel2.setName("jPanel2"); // NOI18N

        jScrollPane7.setName("jScrollPane7"); // NOI18N

        dependenceList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        dependenceList.setName("dependenceList"); // NOI18N
        jScrollPane7.setViewportView(dependenceList);

        addDependenceButton.setText(resourceMap.getString("addDependenceButton.text")); // NOI18N
        addDependenceButton.setName("addDependenceButton"); // NOI18N
        addDependenceButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addDependenceButtonActionPerformed(evt);
            }
        });

        deleteDependenceButton.setText(resourceMap.getString("deleteDependenceButton.text")); // NOI18N
        deleteDependenceButton.setName("deleteDependenceButton"); // NOI18N
        deleteDependenceButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteDependenceButtonActionPerformed(evt);
            }
        });

        lectureBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        lectureBox.setName("lectureBox"); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane7, javax.swing.GroupLayout.DEFAULT_SIZE, 173, Short.MAX_VALUE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(lectureBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE)
                        .addComponent(addDependenceButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(deleteDependenceButton)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(deleteDependenceButton)
                    .addComponent(addDependenceButton)
                    .addComponent(lectureBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane7, javax.swing.GroupLayout.DEFAULT_SIZE, 336, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout lectureManagerPanelLayout = new javax.swing.GroupLayout(lectureManagerPanel);
        lectureManagerPanel.setLayout(lectureManagerPanelLayout);
        lectureManagerPanelLayout.setHorizontalGroup(
            lectureManagerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(lectureManagerPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(lectureManagerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(lectureManagerPanelLayout.createSequentialGroup()
                        .addComponent(addLectureButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(deleteLectureButton))
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 539, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        lectureManagerPanelLayout.setVerticalGroup(
            lectureManagerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, lectureManagerPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(lectureManagerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, lectureManagerPanelLayout.createSequentialGroup()
                        .addGroup(lectureManagerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(addLectureButton)
                            .addComponent(deleteLectureButton))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 388, Short.MAX_VALUE)))
                .addContainerGap())
        );

        tabbedPanel.addTab(resourceMap.getString("课程管理.TabConstraints.tabTitle"), lectureManagerPanel); // NOI18N

        teacherPanel.setName("导师课表"); // NOI18N

        gotoClassFromTeacherButton.setText(resourceMap.getString("gotoClassFromTeacherButton.text")); // NOI18N
        gotoClassFromTeacherButton.setName("gotoClassFromTeacherButton"); // NOI18N
        gotoClassFromTeacherButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                gotoClassFromTeacherButtonActionPerformed(evt);
            }
        });

        jScrollPane8.setName("jScrollPane8"); // NOI18N

        teacherTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        teacherTable.setName("teacherTable"); // NOI18N
        jScrollPane8.setViewportView(teacherTable);

        planSearch1.setFont(resourceMap.getFont("planSearch1.font")); // NOI18N
        planSearch1.setText(resourceMap.getString("planSearch1.text")); // NOI18N
        planSearch1.setName("planSearch1"); // NOI18N

        javax.swing.GroupLayout teacherPanelLayout = new javax.swing.GroupLayout(teacherPanel);
        teacherPanel.setLayout(teacherPanelLayout);
        teacherPanelLayout.setHorizontalGroup(
            teacherPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(teacherPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(teacherPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane8, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 758, Short.MAX_VALUE)
                    .addGroup(teacherPanelLayout.createSequentialGroup()
                        .addComponent(gotoClassFromTeacherButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 421, Short.MAX_VALUE)
                        .addComponent(planSearch1, javax.swing.GroupLayout.PREFERRED_SIZE, 237, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        teacherPanelLayout.setVerticalGroup(
            teacherPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(teacherPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(teacherPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(gotoClassFromTeacherButton)
                    .addComponent(planSearch1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane8, javax.swing.GroupLayout.DEFAULT_SIZE, 388, Short.MAX_VALUE)
                .addContainerGap())
        );

        tabbedPanel.addTab(resourceMap.getString("导师课表.TabConstraints.tabTitle"), teacherPanel); // NOI18N

        markFromTeacherPanel.setName("导师评分"); // NOI18N

        markFromTeacherText.setText(resourceMap.getString("markFromTeacherText.text")); // NOI18N
        markFromTeacherText.setName("markFromTeacherText"); // NOI18N

        markFromTeacherButton.setText(resourceMap.getString("markFromTeacherButton.text")); // NOI18N
        markFromTeacherButton.setName("markFromTeacherButton"); // NOI18N
        markFromTeacherButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                markFromTeacherButtonActionPerformed(evt);
            }
        });

        jScrollPane5.setName("jScrollPane5"); // NOI18N

        markFromTeacherTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        markFromTeacherTable.setName("markFromTeacherTable"); // NOI18N
        jScrollPane5.setViewportView(markFromTeacherTable);
        markFromTeacherTable.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("学生评分.columnModel.title0")); // NOI18N
        markFromTeacherTable.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("学生评分.columnModel.title1")); // NOI18N
        markFromTeacherTable.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("学生评分.columnModel.title2")); // NOI18N
        markFromTeacherTable.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("学生评分.columnModel.title3")); // NOI18N

        javax.swing.GroupLayout markFromTeacherPanelLayout = new javax.swing.GroupLayout(markFromTeacherPanel);
        markFromTeacherPanel.setLayout(markFromTeacherPanelLayout);
        markFromTeacherPanelLayout.setHorizontalGroup(
            markFromTeacherPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(markFromTeacherPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(markFromTeacherPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 758, Short.MAX_VALUE)
                    .addGroup(markFromTeacherPanelLayout.createSequentialGroup()
                        .addComponent(markFromTeacherButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(markFromTeacherText, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        markFromTeacherPanelLayout.setVerticalGroup(
            markFromTeacherPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(markFromTeacherPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(markFromTeacherPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(markFromTeacherButton)
                    .addComponent(markFromTeacherText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 388, Short.MAX_VALUE)
                .addContainerGap())
        );

        tabbedPanel.addTab(resourceMap.getString("导师评分.TabConstraints.tabTitle"), markFromTeacherPanel); // NOI18N

        studentPanel.setName("学生课表"); // NOI18N

        gotoClassFromStudentButton.setText(resourceMap.getString("gotoClassFromStudentButton.text")); // NOI18N
        gotoClassFromStudentButton.setName("gotoClassFromStudentButton"); // NOI18N
        gotoClassFromStudentButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                gotoClassFromStudentButtonActionPerformed(evt);
            }
        });

        planSearch2.setFont(resourceMap.getFont("planSearch2.font")); // NOI18N
        planSearch2.setText(resourceMap.getString("planSearch2.text")); // NOI18N
        planSearch2.setName("planSearch2"); // NOI18N

        jScrollPane9.setName("jScrollPane9"); // NOI18N

        studentTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        studentTable.setName("studentTable"); // NOI18N
        jScrollPane9.setViewportView(studentTable);

        javax.swing.GroupLayout studentPanelLayout = new javax.swing.GroupLayout(studentPanel);
        studentPanel.setLayout(studentPanelLayout);
        studentPanelLayout.setHorizontalGroup(
            studentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(studentPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(studentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane9, javax.swing.GroupLayout.DEFAULT_SIZE, 758, Short.MAX_VALUE)
                    .addGroup(studentPanelLayout.createSequentialGroup()
                        .addComponent(gotoClassFromStudentButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 421, Short.MAX_VALUE)
                        .addComponent(planSearch2, javax.swing.GroupLayout.PREFERRED_SIZE, 237, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        studentPanelLayout.setVerticalGroup(
            studentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(studentPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(studentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(gotoClassFromStudentButton)
                    .addComponent(planSearch2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane9, javax.swing.GroupLayout.DEFAULT_SIZE, 388, Short.MAX_VALUE)
                .addContainerGap())
        );

        tabbedPanel.addTab(resourceMap.getString("学生课表.TabConstraints.tabTitle"), studentPanel); // NOI18N

        markFromStudentPanel.setName("学生评分"); // NOI18N

        jScrollPane4.setName("jScrollPane4"); // NOI18N

        markTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        markTable.setName("学生评分"); // NOI18N
        jScrollPane4.setViewportView(markTable);
        markTable.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("学生评分.columnModel.title0")); // NOI18N
        markTable.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("学生评分.columnModel.title1")); // NOI18N
        markTable.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("学生评分.columnModel.title2")); // NOI18N
        markTable.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("学生评分.columnModel.title3")); // NOI18N

        markButton.setText(resourceMap.getString("markButton.text")); // NOI18N
        markButton.setName("markButton"); // NOI18N
        markButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                markButtonActionPerformed(evt);
            }
        });

        markText.setText(resourceMap.getString("markText.text")); // NOI18N
        markText.setName("markText"); // NOI18N

        javax.swing.GroupLayout markFromStudentPanelLayout = new javax.swing.GroupLayout(markFromStudentPanel);
        markFromStudentPanel.setLayout(markFromStudentPanelLayout);
        markFromStudentPanelLayout.setHorizontalGroup(
            markFromStudentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(markFromStudentPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(markFromStudentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 758, Short.MAX_VALUE)
                    .addGroup(markFromStudentPanelLayout.createSequentialGroup()
                        .addComponent(markButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(markText, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        markFromStudentPanelLayout.setVerticalGroup(
            markFromStudentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(markFromStudentPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(markFromStudentPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(markButton)
                    .addComponent(markText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 388, Short.MAX_VALUE)
                .addContainerGap())
        );

        tabbedPanel.addTab(resourceMap.getString("学生评分.TabConstraints.tabTitle"), markFromStudentPanel); // NOI18N

        classInfoPanel.setName("教室信息"); // NOI18N

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        classInfoTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        classInfoTable.setName("classInfoTable"); // NOI18N
        jScrollPane2.setViewportView(classInfoTable);

        planSearch3.setFont(resourceMap.getFont("planSearch3.font")); // NOI18N
        planSearch3.setText(resourceMap.getString("planSearch3.text")); // NOI18N
        planSearch3.setName("planSearch3"); // NOI18N

        javax.swing.GroupLayout classInfoPanelLayout = new javax.swing.GroupLayout(classInfoPanel);
        classInfoPanel.setLayout(classInfoPanelLayout);
        classInfoPanelLayout.setHorizontalGroup(
            classInfoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, classInfoPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(classInfoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 758, Short.MAX_VALUE)
                    .addComponent(planSearch3, javax.swing.GroupLayout.PREFERRED_SIZE, 237, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        classInfoPanelLayout.setVerticalGroup(
            classInfoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(classInfoPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(planSearch3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 390, Short.MAX_VALUE)
                .addContainerGap())
        );

        tabbedPanel.addTab(resourceMap.getString("教室信息.TabConstraints.tabTitle"), classInfoPanel); // NOI18N

        registerPanel.setName("学生注册"); // NOI18N

        registerButton.setText(resourceMap.getString("registerButton.text")); // NOI18N
        registerButton.setName("registerButton"); // NOI18N
        registerButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                registerButtonActionPerformed(evt);
            }
        });

        jScrollPane6.setName("jScrollPane6"); // NOI18N

        registerTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        registerTable.setName("registerTable"); // NOI18N
        jScrollPane6.setViewportView(registerTable);

        javax.swing.GroupLayout registerPanelLayout = new javax.swing.GroupLayout(registerPanel);
        registerPanel.setLayout(registerPanelLayout);
        registerPanelLayout.setHorizontalGroup(
            registerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(registerPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(registerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 758, Short.MAX_VALUE)
                    .addComponent(registerButton))
                .addContainerGap())
        );
        registerPanelLayout.setVerticalGroup(
            registerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(registerPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(registerButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 388, Short.MAX_VALUE)
                .addContainerGap())
        );

        tabbedPanel.addTab(resourceMap.getString("学生注册.TabConstraints.tabTitle"), registerPanel); // NOI18N

        mainPanel.add(tabbedPanel);

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        menuSwitchAccount.setText(resourceMap.getString("menuSwitchAccount.text")); // NOI18N
        menuSwitchAccount.setName("menuSwitchAccount"); // NOI18N
        menuSwitchAccount.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                menuSwitchAccountActionPerformed(evt);
            }
        });
        fileMenu.add(menuSwitchAccount);

        jSeparator1.setName("jSeparator1"); // NOI18N
        fileMenu.add(jSeparator1);

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(jdh.JdhApp.class).getContext().getActionMap(JdhView.class, this);
        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setText(resourceMap.getString("exitMenuItem.text")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        statusPanel.setName("statusPanel"); // NOI18N

        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        progressBar.setName("progressBar"); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 770, Short.MAX_VALUE)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusMessageLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 602, Short.MAX_VALUE)
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(statusMessageLabel)
                    .addComponent(statusAnimationLabel)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(3, 3, 3))
        );

        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
    }// </editor-fold>//GEN-END:initComponents

    private void tabbedPanelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tabbedPanelMouseClicked
        java.awt.Component tab = tabbedPanel.getSelectedComponent();
        if (tab == oldTab) return;
        System.out.println(tab.getName());
        oldTab = tab;
        if (tab == userManagerPanel)
            gotoUserManager();
        else if (tab == planManagerPanel)
            gotoPlanManager();
        else if (tab == teacherPanel)
            gotoTeacherReport();
        else if (tab == studentPanel)
            gotoStudentReport();
        else if (tab == classInfoPanel)
            gotoClassInfo();
        else if (tab == classManagerPanel)
            gotoClassManager();
        else if (tab == lectureManagerPanel)
            gotoLectureManager();
        else if (tab == markFromStudentPanel)
            gotoMarkFromStudent();
        else if (tab == markFromTeacherPanel)
            gotoMarkFromTeacher();
        else if (tab == registerPanel)
            gotoRegisterManager();
        else
            gotoIntro();
    }//GEN-LAST:event_tabbedPanelMouseClicked

    private void userManagerTypeStudentStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_userManagerTypeStudentStateChanged
        
    }//GEN-LAST:event_userManagerTypeStudentStateChanged

    private void userManagerTypeStudentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_userManagerTypeStudentActionPerformed
        if (userStudentModel != null)
            userTable.setModel(userStudentModel);// TODO add your handling code here:
    }//GEN-LAST:event_userManagerTypeStudentActionPerformed

    private void userManagerTypeTeacherActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_userManagerTypeTeacherActionPerformed
        if (userTeacherModel != null)
            userTable.setModel(userTeacherModel);// TODO add your handling code here:
    }//GEN-LAST:event_userManagerTypeTeacherActionPerformed

    private void userManagerTypeAdminActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_userManagerTypeAdminActionPerformed
        if (userAdminModel != null)
            userTable.setModel(userAdminModel);// TODO add your handling code here:
    }//GEN-LAST:event_userManagerTypeAdminActionPerformed

    private void deleteUserButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteUserButtonActionPerformed
        DataModel model = (DataModel) userTable.getModel();
        int i = userTable.getSelectedRowCount();
        int row = 0;
        while (i -- > 0){
            model.delete(row = userTable.getSelectedRow());
        }
        if (row > userTable.getRowCount() - 1) row = userTable.getRowCount() - 1;
        else if (row < 0) row = 0;
        userTable.setRowSelectionInterval(row, row);
        userTable.updateUI();
    }//GEN-LAST:event_deleteUserButtonActionPerformed

    private void addUserButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addUserButtonActionPerformed
        DataModel model = (DataModel) userTable.getModel();
        model.insert();
        userTable.setRowSelectionInterval(userTable.getRowCount() - 1, userTable.getRowCount() - 1);
        userTable.updateUI();
    }//GEN-LAST:event_addUserButtonActionPerformed

    private void menuSwitchAccountActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuSwitchAccountActionPerformed
        this.getFrame().setVisible(false);//.dispose();
        login();
        this.getFrame().setVisible(true);
    }//GEN-LAST:event_menuSwitchAccountActionPerformed

    private void addLectureButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addLectureButtonActionPerformed
        DataModel model = (DataModel) lectureTable.getModel();
        model.insert();
        //lectureTable.setRowSelectionInterval(lectureTable.getRowCount() - 1, lectureTable.getRowCount() - 1);
        lectureTable.updateUI();

    }//GEN-LAST:event_addLectureButtonActionPerformed

    private void deleteLectureButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteLectureButtonActionPerformed
        DataModel model = (DataModel) lectureTable.getModel();
        int i = lectureTable.getSelectedRowCount();
        int row = 0;
        while (i -- > 0){
            model.delete(row = lectureTable.getSelectedRow());
        }
        if (row > lectureTable.getRowCount() - 1) row = lectureTable.getRowCount() - 1;
        else if (row < 0) row = 0;
        lectureTable.setRowSelectionInterval(row, row);
        lectureTable.updateUI();
    }//GEN-LAST:event_deleteLectureButtonActionPerformed

    private void markButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_markButtonActionPerformed
        int row = markTable.getSelectedRow();
        Do.markFromStudent(markTable.getValueAt(row, 0).toString(),
                markTable.getValueAt(row, 1).toString(),
                Integer.valueOf(markText.getText()));
    }//GEN-LAST:event_markButtonActionPerformed

    private void markFromTeacherButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_markFromTeacherButtonActionPerformed
        int row = markFromTeacherTable.getSelectedRow();
        Do.markFromTeacher(markFromTeacherTable.getValueAt(row, 0).toString(),
                markFromTeacherTable.getValueAt(row, 1).toString(),
                Integer.valueOf(markFromTeacherText.getText()));
        ((DataModel)markFromTeacherTable.getModel()).refresh();
        markFromTeacherTable.updateUI();
    }//GEN-LAST:event_markFromTeacherButtonActionPerformed

    private void addDependenceButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addDependenceButtonActionPerformed
        String firstName = lectureBox.getSelectedItem().toString();
        int row = lectureTable.getSelectedRow();
        int column = ((DataModel)lectureTable.getModel()).findColumn("ID");
        String secondID = lectureTable.getValueAt(row, column).toString();
        Do.addDependence(firstName, secondID);
        ((LineModel)dependenceList.getModel()).refresh();
        dependenceList.updateUI();
    }//GEN-LAST:event_addDependenceButtonActionPerformed

    private void registerButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_registerButtonActionPerformed
        int row = registerTable.getSelectedRow();
        String planName = registerTable.getValueAt(row, 0).toString();
        Do.registerPlan(currentUserID, planName);
        ((DataModel)lectureTable.getModel()).refresh();

    }//GEN-LAST:event_registerButtonActionPerformed

    private void deleteDependenceButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteDependenceButtonActionPerformed
        String firstName = dependenceList.getSelectedValue().toString();
        int row = lectureTable.getSelectedRow();
        int column = ((DataModel)lectureTable.getModel()).findColumn("ID");
        String secondID = lectureTable.getValueAt(row, column).toString();
        Do.deleteDependence(firstName, secondID);
    }//GEN-LAST:event_deleteDependenceButtonActionPerformed

    private void lectureTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lectureTableMouseClicked
        int row = lectureTable.getSelectedRow();
        int column = ((DataModel)lectureTable.getModel()).findColumn("ID");
        System.out.print(row + "," + column);
        String id = lectureTable.getValueAt(row, column).toString();
        dependenceModel.setSelect(String.format(dependenceTemplate, id));
        dependenceModel.refresh();
        dependenceList.updateUI();
    }//GEN-LAST:event_lectureTableMouseClicked

    private void gotoClassFromTeacherButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_gotoClassFromTeacherButtonActionPerformed
        int row = this.teacherTable.getSelectedRow();
        int column = ((DataModel)teacherTable.getModel()).findColumn("LECTURE");
        //if (column == -1) column = 1;
        String name = this.teacherTable.getValueAt(row, column).toString();
        String id = Do.name2ID("LECTURES", name);
        this.classInfoTable.setModel(DataModel.getClassInfoModel(id, currentUserID));
        this.tabbedPanel.setSelectedComponent(this.classInfoPanel);
    }//GEN-LAST:event_gotoClassFromTeacherButtonActionPerformed

    private void gotoClassFromStudentButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_gotoClassFromStudentButtonActionPerformed
        int row = studentTable.getSelectedRow();
        int lectureColumn = ((DataModel)teacherTable.getModel()).findColumn("LECTURE");
        int teacherColumn = ((DataModel)teacherTable.getModel()).findColumn("TEACHER");
        String lectureName = studentTable.getValueAt(row, lectureColumn).toString();
        String teacherName = studentTable.getValueAt(row, teacherColumn).toString();
        String lecture = Do.name2ID("LECTURES", lectureName);
        String teacher = Do.name2ID("TEACHERS", teacherName);
        this.classInfoTable.setModel(DataModel.getClassInfoModel(lecture, teacher));
        this.tabbedPanel.setSelectedComponent(this.classInfoPanel);
    }//GEN-LAST:event_gotoClassFromStudentButtonActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addDependenceButton;
    private javax.swing.JButton addLectureButton;
    private javax.swing.JButton addUserButton;
    private javax.swing.JPanel classInfoPanel;
    private javax.swing.JTable classInfoTable;
    private javax.swing.JButton deleteDependenceButton;
    private javax.swing.JButton deleteLectureButton;
    private javax.swing.JButton deleteUserButton;
    private javax.swing.JList dependenceList;
    private javax.swing.JButton gotoClassFromStudentButton;
    private javax.swing.JButton gotoClassFromTeacherButton;
    private javax.swing.JPanel introPanel;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel14;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JScrollPane jScrollPane7;
    private javax.swing.JScrollPane jScrollPane8;
    private javax.swing.JScrollPane jScrollPane9;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JComboBox lectureBox;
    private javax.swing.JPanel lectureManagerPanel;
    private javax.swing.JTable lectureTable;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JButton markButton;
    private javax.swing.JPanel markFromStudentPanel;
    private javax.swing.JButton markFromTeacherButton;
    private javax.swing.JPanel markFromTeacherPanel;
    private javax.swing.JTable markFromTeacherTable;
    private javax.swing.JTextField markFromTeacherText;
    private javax.swing.JTable markTable;
    private javax.swing.JTextField markText;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JMenuItem menuSwitchAccount;
    private javax.swing.JTextField planSearch1;
    private javax.swing.JTextField planSearch2;
    private javax.swing.JTextField planSearch3;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JButton registerButton;
    private javax.swing.JPanel registerPanel;
    private javax.swing.JTable registerTable;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    private javax.swing.JPanel studentPanel;
    private javax.swing.JTable studentTable;
    private javax.swing.JTabbedPane tabbedPanel;
    private javax.swing.JPanel teacherPanel;
    private javax.swing.JTable teacherTable;
    private javax.swing.JPanel userManagerPanel;
    private javax.swing.JRadioButton userManagerTypeAdmin;
    private javax.swing.ButtonGroup userManagerTypeGroup;
    private javax.swing.JRadioButton userManagerTypeStudent;
    private javax.swing.JRadioButton userManagerTypeTeacher;
    private javax.swing.JTextField userSearch;
    private javax.swing.JTable userTable;
    private javax.swing.ButtonGroup userType;
    // End of variables declaration//GEN-END:variables

    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;

    private JDialog aboutBox;

    private JdhLoginDialog loginDialog = null;
    private Backend backend = null;

    int currentUserType;
    String currentUserID;
    java.awt.Component oldTab = null;

    boolean toInitUser = true;
    boolean toInitPlan = true;
    boolean toInitTeacher = true;
    boolean toInitStudent = true;
    boolean toInitClass = true;
    boolean toInitLecture = true;
    boolean toInitMarkFromStudent = true;
    boolean toInitMarkFromTeacher = true;
    boolean toInitRegister = true;
    // 用户管理选项卡的表格的数据源模型
    DataModel userAdminModel = null;
    DataModel userTeacherModel = null;
    DataModel userStudentModel = null;
    // 课程依赖信息模型
    LineModel dependenceModel = null;
    // 培训计划信息管理
    PlanPanel planManagerPanel = null;
    // 课堂信息管理
    ClassPanel classManagerPanel = null;

    String dependenceTemplate = "SELECT NAME FROM LECTURES, DEPENDENCES " +
            "WHERE LECTURES.ID = FIRST AND SECOND = '%S'";
    
    private void gotoIntro(){
        tabbedPanel.setSelectedComponent(introPanel);
        tabbedPanel.setSelectedIndex(tabbedPanel.getSelectedIndex());
        oldTab = introPanel;
    }

    private void gotoUserManager(){
        if (toInitUser){
            toInitUser = false;
            userAdminModel = DataModel.getUserAdminModel();
            userTeacherModel = DataModel.getUserTeacherModel();
            userStudentModel = DataModel.getUserTeacherModel();
        }
        if (userManagerTypeAdmin.isSelected()) userTable.setModel(userAdminModel);
        else if (userManagerTypeTeacher.isSelected()) userTable.setModel(userTeacherModel);
        else userTable.setModel(userStudentModel);
    }

    private void gotoPlanManager(){
        if (toInitPlan){
            toInitPlan = false;
            planManagerPanel.initPlanPanel();
        }
        planManagerPanel.wakeupPlanPanel();
    }

    private void gotoClassManager(){
        if (toInitClass){
            toInitClass = false;
            classManagerPanel.initClassPanel();
        }
        //classManagerPanel.wakeupClassPanel();
    }

    private void gotoTeacherReport(){
        if (toInitTeacher){
            toInitTeacher = false;
            teacherTable.setModel(DataModel.getTeacherModel(currentUserID));
        }
    }

    private void gotoStudentReport(){
        if (toInitStudent){
            toInitStudent = false;
            studentTable.setModel(DataModel.getStudentModel(currentUserID));
            dependenceModel = new LineModel();
        }
    }

    private void gotoMarkFromStudent(){
        if (toInitMarkFromStudent){
            toInitMarkFromStudent = false;
            markTable.setModel(DataModel.getMarkFromStudentModel(currentUserID));
        }
    }
    private void gotoMarkFromTeacher(){
        if (toInitMarkFromTeacher){
            toInitMarkFromTeacher = false;
            markFromTeacherTable.setModel(DataModel.getMarkFromTeacherModel(currentUserID));
        }
    }

    private void gotoLectureManager(){
        if (toInitLecture){
            toInitLecture = false;
            dependenceModel = new LineModel();
            dependenceList.setModel(dependenceModel);
            lectureTable.setModel(DataModel.getLectureModel());
            lectureBox.setModel(LineBoxModel.getLectureBoxModel());
        }
    }

    private void gotoRegisterManager(){
        if (toInitRegister){
            toInitRegister = false;
            registerTable.setModel(DataModel.getRegisterModel(currentUserID));
        }
    }

    private void gotoClassInfo(){
//        if (toInitClassInfo){
//            toInitClassInfo = false;
//            classTable.setModel(DataModel.getClassInfoModel());
//        }
    }

    private void tabbedPanelInitial(){
        planManagerPanel = new PlanPanel(backend);
        planManagerPanel.setName("培训计划管理");
        classManagerPanel = new ClassPanel(backend);
        classManagerPanel.setName("课堂列表");

        javax.swing.JPanel[] adminTabs = {
            introPanel, userManagerPanel, planManagerPanel, 
            classManagerPanel, lectureManagerPanel};
        javax.swing.JPanel[] teacherTabs = {
            introPanel, teacherPanel, classInfoPanel,
            markFromTeacherPanel};
        javax.swing.JPanel[] studentTabs = {
            introPanel, studentPanel, classInfoPanel,
            markFromStudentPanel, registerPanel};

        if (currentUserType == 0)
            tabbedPanelShow(adminTabs);
        else if (currentUserType == 1)
            tabbedPanelShow(teacherTabs);
        else
            tabbedPanelShow(studentTabs);
        gotoIntro();
    }
    
    private void tabbedPanelShow(javax.swing.JPanel[] tabs){
        tabbedPanel.removeAll();
        for(int i = 0; i < tabs.length; i ++){
            tabbedPanel.add(tabs[i]);
            tabbedPanel.setTitleAt(i, tabs[i].getName());
        }
    }
}
